package problem424;

//424. 替换后的最长重复字符
//https://leetcode.cn/problems/longest-repeating-character-replacement/

class Solution {
    public int characterReplacement(String s, int k) {
        int ret = 0;
        int n = s.length();
        int maxCount = 0;
        int[] hash = new int[128]; 
        for(int i = 0, j = 0; j<n; j++) {
            hash[s.charAt(j)]++;
            maxCount = Math.max(maxCount, hash[s.charAt(j)]);
            if(j - i + 1 > maxCount + k) {
                hash[s.charAt(i)]--;
                i++;
            }
            ret = Math.max(ret, j-i+1);
        }
        return ret;
    }
}